﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class FND_VAT : RibbonForm
    {
        public FND_VAT()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public string VatCodeName { get; set; }
        public double TaxRate { get; set; }
        public string IsTaxInclusive { get; set; }
        
        void BindTaxCode()
        {
            TaxManager oTaxManager = new TaxManager();

            oTaxManager.ConnectionString = this.ConnectionString;
            oTaxManager.Open();
            DataTable oTable = oTaxManager.GetTaxCodes();
            oTaxManager.Close();

            gridControl1.DataSource = oTable;
            gridControl1.Refresh();
        }
        private void FND_VAT_Load(object sender, EventArgs e)
        {
            BindTaxCode();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int[] iRow = gridView1.GetSelectedRows();

            int iRowNum = iRow[0];

            this.VatCodeName = gridView1.GetRowCellValue(iRowNum, gridView1.Columns["Dscription"]).ToString();
            this.TaxRate = Convert.ToDouble(gridView1.GetRowCellValue(iRowNum, gridView1.Columns["Rate"]).ToString());
            this.IsTaxInclusive = gridView1.GetRowCellValue(iRowNum, gridView1.Columns["IsInclusive"]).ToString();

            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }
    }
}
